package com.cordys.opensource.crom;

import com.cordys.cpc.bsf.classinfo.AttributeInfo;

/**
 * Simple wrapper class for AttributeInfo.
 * It also holds the name of the attribute as it is passed into a sql query.
 */
class BusObjectAttribute
{
	private final AttributeInfo dbAttribute;
	private final AttributeInfo domainAttribute;
	private final String aliasName;
	private final boolean isParentKey;

	BusObjectAttribute(AttributeInfo dbAttribute, String tableAlias, AttributeInfo domainAttribute, boolean isParentKey)
	{
		this.dbAttribute = dbAttribute;
		this.domainAttribute = domainAttribute;
		String childColumnName = dbAttribute.getColumnName();
		this.aliasName = tableAlias+"."+childColumnName;
		this.isParentKey = isParentKey;
	}
	
	String getAliasName()
	{
		return aliasName;
	}
	
	AttributeInfo getDBAttributeInfo()
	{
		return dbAttribute;
	}
	
	AttributeInfo getDomainAttributeInfo()
	{
		return domainAttribute;
	}
	
	boolean isParentKey()
	{
		return isParentKey;
	}
	
	public String toString()
	{
		if (aliasName.equals(dbAttribute.getColumnName()))
		{
			return aliasName;
		}
		return dbAttribute.getName()+" as "+aliasName;
	}
}

